home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 22 / Cream of the Crop 22.iso / program / cgazv4n3.zip / EMSDEMO.C < prev    next >
C/C++ Source or Header  |  1990-02-04  |  3KB  |  76 lines

  1. /****************  EMSDEMO.C  ---  Listing 2  ******************
  2. *
  3. *    This program demonstrates the use of the expanded memory functions
  4. *    defined in Listing 1 (EMS.C).  Validated for Microsoft and Turbo C
  5. *
  6. *    Copyright (C) Michael J. Young, 1989.  All rights reserved.
  7. *    May be used freely for non-commercial purposes.
  8. ***************************************************************/
  9.  
  10. #include <CONIO.H>
  11. #include <DOS.H>
  12. #include <MALLOC.H>
  13. #include <PROCESS.H>
  14. #include <STDIO.H>
  15. #include <STRING.H>
  16.  
  17. #include "EMS.H"
  18.  
  19. void ScrClear (unsigned char StartRow,unsigned char StartCol,
  20.                unsigned char StopRow,unsigned char StopCol);
  21.  
  22. void main (void)
  23. {
  24.      char far *Buffer;
  25.      unsigned char far *PtrVideoMode = (unsigned char far *)0x00400049;
  26.      unsigned int VideoSeg;
  27.  
  28.      if (EmsInstalled () && EmsPagesAvail () >= 1)
  29.      {
  30.           Buffer = EmsAlloc (1);
  31.           EmsMap (0,-1,-1,-1);
  32.           printf ("Using expanded memory to save the screen.\n");
  33.      } /* end if EMS is installed */
  34.  
  35.      else   /* EMS not installed */
  36.      {
  37.           Buffer = (char far *) malloc (4000);
  38.           if (FP_OFF (Buffer) == NULL)
  39.           {
  40.                fprintf (stderr,"Sorry, no memory free for saving screen.\n");
  41.                exit (1);
  42.           }
  43.           printf ("Using heap memory to save the screen.\n");
  44.      } /* end if EMS not installed */
  45.  
  46.      VideoSeg = (*PtrVideoMode == 7) ? 0xB000 : 0xB800;
  47.      printf ("Press any key to save the screen data and clear the screen.\n");
  48.      getch ();
  49.      movedata (VideoSeg,0,FP_SEG (Buffer),FP_OFF (Buffer),4000);
  50.      ScrClear (0,0,24,79);
  51.      printf ("Press any key to restore the screen data...");
  52.      getch ();
  53.      movedata (FP_SEG (Buffer),FP_OFF (Buffer),VideoSeg,0,4000);
  54.      EmsFree ();
  55.  
  56. } /* end main */
  57.  
  58.  
  59. void ScrClear (unsigned char StartRow,unsigned char StartCol,
  60.                unsigned char StopRow,unsigned char StopCol)
  61. /*
  62.      This function clears the rectangular section of the screen specified
  63.      by the four parameters.
  64. */
  65. {
  66.      union REGS Reg;
  67.  
  68.      Reg.h.bh = 0x07;         /* Use normal, white on black video attribute.*/
  69.      Reg.h.ch = StartRow;     /* CH specifies start row.                    */
  70.      Reg.h.cl = StartCol;     /* CL specifies start column.                 */
  71.      Reg.h.dh = StopRow;      /* DH specifies stop row.                     */
  72.      Reg.h.dl = StopCol;      /* DL specifies stop column.                  */
  73.      Reg.x.ax = 0x0600;       /* BIOS scroll page up function.              */
  74.      int86 (0x10,&Reg,&Reg);  /* Invoke BIOS video services.                */
  75.  
  76. } /* end ScrClear */